﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmVentas.aspx.cs" Inherits="Box.Cliente.Ventas.frmVentas" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#<%= txtRuc.ClientID %>").keypress(function (e) {

                if (e.shiftKey) {
                    e.preventDefault();
                }
                else {
                    var key = window.Event ? e.which : e.keyCode;
                    return ((key >= 48 && key <= 57) || (key == 8) || (key==13));

                }
            });
            
        });
    </script>
    
    <div class="span12">
		<div class="span8">		    
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3><b>Información de la Venta</b></h3>
				</div>
				<div class="panel-body">					
					<asp:UpdatePanel runat="server" ID="upClientes">
						<ContentTemplate>
							<table>
								<tr>
									<td><label>RUC/DNI:</label></td>
									<td>
                                    <div class="input-group">
                                    <asp:TextBox ID="txtRuc" MaxLength="11" class="form-control" placeholder="RUC/DNI" runat="server"/>
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                        <ajaxToolkit:ModalPopupExtender runat="server"
                                        BackgroundCssClass="FondoAplicacion" CancelControlID="btnCancelar"
                                        PopupControlID="pnlCliente"
                                         DynamicServicePath="" Enabled="True"
                                         TargetControlID="txtRuc"
                                         ID="txtRuc_ModalPopupExtender"></ajaxToolkit:ModalPopupExtender>
                                    </div>
   
									</td>
									<td>
                                        <asp:Button runat="server" Text="..." ID="btnBuscarCliente" 
                                        class="glyphicon glyphicon-remove label label-danger" OnClick="btnBuscarCliente_Click"/>
									</td><td> </td><td> </td><td></td>
                                    <td><label>Codigo</label></td>
									<td><asp:TextBox ID="txtCodigo" runat="server" CssClass="form-control input-sm" ReadOnly="True"/></td>
                                    <td><label>Tipo de Documentos</label></td>
                                    <td>
                                        <asp:DropDownList 
                                                    CssClass="form-control input-sm"
                                                    ID="cbTipoDocumento"
                                                    ItemType="Box.Entities.TipoDocumento"
                                                    DataTextField="NombreTipoDocumento"
                                                    DataValueField="Id"
                                                    runat="server"
                                                    SelectMethod="GetTipoDocumentos"/>
                                    </td>
                                    									
								</tr>
								<tr>
									<td><label>Cliente:</label></td>
									<td><asp:TextBox ID="txtCliente" CssClass="form-control input-sm" ReadOnly="True" runat="server"/></td>
									<td> </td><td> </td><td> <td></td>                                                                      
                                    									
								</tr>
								<tr>								    
									<td><label>Dirección:</label></td>
									<td><asp:TextBox ID="txtDireccion" CssClass="form-control input-sm" ReadOnly="True" runat="server"/></td>
									<td> </td><td> </td><td> </td><td></td>
                                    <td><label>Fecha:</label></td>
									<td>
										<asp:TextBox runat="server" CssClass="form-control input-sm" ReadOnly="True" ID="txtFecha"></asp:TextBox>
									</td> 
								</tr>
							</table>
						</ContentTemplate>
						<Triggers>
							<asp:AsyncPostBackTrigger ControlID="btnBuscarCliente" EventName="Click"/>
						</Triggers>
					</asp:UpdatePanel>
                    <br />
                <div class="row">
                        <div class="col-md-6 .col-md-push-3">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                   <h3>Productos</h3>
                                 </div>
                            <div class="panel-body">
                     <table>
						<tr>
							<td><label>Criterio:</label></td>
							<td><asp:TextBox ID="txtCriterio" MaxLength="50" placeholder="Buscar" runat="server"/></td>
							<td><asp:Button runat="server" CssClass="btn btn-primary btn-sm" Text="Buscar" ID="btnBuscar"/></td>
						</tr>
					 </table>
				
					<asp:UpdatePanel runat="server" ID="upProducto">
						<ContentTemplate>
							<asp:ListView ID="lvProductos"
								 ItemType="Box.Entities.Producto" SelectMethod="GetProductos"
								runat="server" OnItemCommand="lvProductos_ItemCommand" >
								<EmptyDataTemplate>
									<b>No se han encontrado Productos..!!</b>
								</EmptyDataTemplate>
								<LayoutTemplate>
									<table class="table table-hover table-condensed">
										<thead>
											<tr>
												<th>Descripción</th>
												<th>Precio</th>
                                                <th>Talla</th>
												<th>Stock</th>
												<th>Acciones</th>
											</tr>
										</thead>
										<tbody>
											<tr id="itemPlaceholder" runat="server"/>
										</tbody>
									 </table>
									<asp:DataPager ID="dpProductos" PagedControlID="lvProductos" runat="server" PageSize="2">
										<Fields>
											<asp:NextPreviousPagerField
												ButtonType="Link"
												ShowFirstPageButton="True"
												ShowLastPageButton="True"
												ShowNextPageButton="True"
												ShowPreviousPageButton="True"
												/>
										</Fields>
									</asp:DataPager>
								</LayoutTemplate>
								<ItemTemplate>
									<tr>
										<th><%# Item.NombreProducto %></th>
                                        
										<th><%# Item.Precio %></th>
										<th><%# Item.TallaProducto %></th>
                                        <th><%# Item.Stock %></th>
										<th>
											<asp:Button ID="btnAgregar"
												Text="+" CommandName="AddDetalle"
												CommandArgument="<%# Item.Id %>"
												CssClass="btn btn-success" Width="35px" Height="35px" runat="server"/>
										</th>
									</tr>
								</ItemTemplate>
							</asp:ListView>
						</ContentTemplate>
						<Triggers>
							<asp:AsyncPostBackTrigger ControlID="btnBuscar" EventName="Click"/>                            
						</Triggers>
					</asp:UpdatePanel>
                            </div>
                        </div>
                        </div>
                    <div class="col-md-6 .col-md-push-3">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                   <h3>Productos</h3>
                                 </div>
                            <div class="panel-body">
                       <asp:UpdatePanel runat="server" ID="upDetalle">
							<ContentTemplate>
								<asp:ListView ID="lvDetalleVenta" runat="server" OnItemCommand="lvDetalleVenta_ItemCommand">
									<EmptyDataTemplate>
										<table class="table table-hover table-condensed">
											<thead>
												<tr>
													<th>Descripcion</th>
													<th>Cantidad</th>
													<th>Precio</th>
													<th>Monto</th>
													<th>Acciones</th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td colspan="6">
														<h3>No tiene productos agregados a su detalle..!!</h3>
													</td>
												</tr>
											</tbody>
											<tfoot>
												<tr>
													<td></td>
													<td></td>
													<td></td>
													<td></td>
													<td></td>
												</tr>
											</tfoot>
										</table>
									</EmptyDataTemplate>
									<LayoutTemplate>
										<table class="table table-hover table-condensed">
											<thead>
												<tr>
													<th>Descripcion</th>
													<th>Cantidad</th>
													<th>Precio</th>
													<th>Monto</th>
													<th>Acciones</th>
												</tr>
											</thead>
											<tbody>
												<tr id="itemPlaceholder" runat="server"/>
											</tbody>
											<tfoot>
												<tr>
													<td>
														<%--<asp:Button runat="server"
															ID="btnActualizarDetalle"
															Text="Actualizar Detalle"
															CommandName="ActualizarDetalle" />--%>
													</td>
													<td></td>
													<td></td>
													<td><h3>Total:</h3></td>
													<td><h3><asp:Label ID="lblTotal" runat="server"></asp:Label></h3></td>
                                                    <td></td>														
												</tr>
											</tfoot>
										</table>
									</LayoutTemplate>                                
									<ItemTemplate>
										<tr>
                                           
											<td><%# Eval("Producto.NombreProducto") %></td>
											<td><asp:TextBox AutoPostBack="False" OnTextChanged="txtCantidad_TextChanged" runat="server" MaxLength="3" ID="txtCantidad" Text='<%# Bind("Cantidad") %>' Width="60px"/></td>
                                            <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" TargetControlID="txtCantidad" FilterType="Numbers"  runat="server"></ajaxToolkit:FilteredTextBoxExtender>
											<td><asp:TextBox runat="server" AutoPostBack="False" OnTextChanged="txtPrecio_TextChanged" MaxLength="3" ID="txtPrecio" Text='<%# Bind("PrecioUnit") %>' Width="60px"/></td>
						                    <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtPrecio" FilterType="Numbers, Custom"  ValidChars="."  runat="server"></ajaxToolkit:FilteredTextBoxExtender>

                                            <td><%# Eval("Monto") %></td>
											<td>
												<asp:Button ID="Button1" runat="server" Text="Quitar"
													CssClass="btn btn-danger btn-sm"
													CommandName="QuitarDetalle"
													CommandArgument='<%# Eval("IdProducto") %>'/>
											</td>
										</tr>
									</ItemTemplate>
								</asp:ListView>
							</ContentTemplate>
							<Triggers>
								<asp:AsyncPostBackTrigger ControlID="lvDetalleVenta" EventName="ItemCommand"/>
								<asp:AsyncPostBackTrigger ControlID="lvProductos" EventName="ItemCommand"/>
								<asp:AsyncPostBackTrigger ControlID="btnGuardar" EventName="Click"/>
							</Triggers>
						</asp:UpdatePanel>

                            </div>
                        </div>
                        </div>
                 </div>

		 
							
				</div>
				<div class="panel-footer">
					<asp:Button runat="server" ID="btnGuardar" CssClass="btn btn-success" Text="Guardar" OnClick="btnGuardar_Click"/>
					<asp:Button runat="server" ID="btnLimpiar" CssClass="btn btn-danger" Text="atrás" OnClick="btnCancelar_Click" OnClientClick="return confirm('Desea  salir a Listar Ventas');"/>

				</div>
			</div>
		</div>
	</div>
    
    <asp:Panel runat="server" ID="pnlCliente" CssClass="panel panel-primary">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h1>Clientes</h1>
            </div>
            <div class="panel-body">
                <table>
                    <tr>
                        <td>Criterio:</td>
                        <td><asp:TextBox runat="server" ID="txtCriterioCliente" CssClass="form-control input-sm"></asp:TextBox></td>
                        <td><asp:Button runat="server" ID="btnBuscarPopUP" Text="Buscar" CssClass="btn btn-success"/></td>
                    </tr>
                </table>
                <br />
                <br />
                <asp:GridView runat="server" ID="gridCliente" DataKeyNames="RucCliente"
                    CssClass="table table-responsive" AutoGenerateColumns="False"
                     DataSourceID="odsCliente"
                     OnSelectedIndexChanged="gridCliente_SelectedIndexChanged">

                    <Columns>
                        <asp:CommandField SelectImageUrl="../Images/orderedList2.png" ShowSelectButton="True" />                        
                        <asp:BoundField DataField="NombreCliente" HeaderText="Cliente" SortExpression="NombreCliente" />
                        <asp:BoundField DataField="RucCliente" HeaderText="Ruc" SortExpression="RucCliente" />
                        <asp:BoundField DataField="DireccionCliente" HeaderText="Dirección" SortExpression="DireccionCliente" />                        
                        <asp:BoundField DataField="TelefonoCliente" HeaderText="Teléfono" SortExpression="TelefonoCliente" />                    
                    </Columns>
                     
                    
                </asp:GridView>
                
                <asp:ObjectDataSource ID="odsCliente" runat="server" OnObjectCreating="odsCliente_ObjectCreating" SelectMethod="GetFromClientesByCriterio" TypeName="Box.BL.ClienteBL">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="txtCriterioCliente" Name="criterio" PropertyName="Text" Type="String" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                
            </div>
            <div class="panel-footer"><asp:Button runat="server" ID="btnCancelar" Text="Cerrar" CssClass="btn btn-danger btn-sm"/></div>
        </div>
    </asp:Panel>

	 <script type="text/javascript">
 	    $(function() {

 	       
 	        if ($("input[name*=txtCantidad]").change() == null || $("input[name*=txtCantidad]").val()==0) {
 	            alert('La cantidad tiene un valor no permitido');
 	        }
 	    });
 	</script>
</asp:Content>
